package tree;

public class CreateTree {

    /*
     * 构造一个二叉树
     *
     *          1
     *           \
     *            2
     *            /
     *           3
     *
     * @return
     */
    public static TreeNode createBinaryTree1() {
        TreeNode root;
        // 构造二叉树的根节点，根节点的值为1
        root = new TreeNode(1);
        //构造二叉树的左子树的根节点(左子树为null)
        root.setLeft(null);
        // 构造二叉树的右子树的根节点
        TreeNode right = new TreeNode(2);
        root.setRight(right);
        // 构造右子树根节点的左子树
        TreeNode right1 = new TreeNode(3);
        right.setLeft(right1);
        right1.setRight(null);
        return root;
    }
    /*
     * 构造一个二叉树
     *
     *          1
     *         / \
     *        2   3
     *       / \ / \
     *      4  5 6  7
     *
     * @return
     */

    public static TreeNode createBinaryTree2() {

        // 构造二叉树的根节点，根节点的值为1
        TreeNode root = new TreeNode(1);

        //构造二叉树的左子树的根节点
        TreeNode left1 = new TreeNode(2);
        root.setLeft(left1);

        // 构造二叉树的右子树的根节点
        TreeNode right1 = new TreeNode(3);
        root.setRight(right1);

        TreeNode left2 = new TreeNode(4);
        TreeNode right2 = new TreeNode(5);
        left1.setLeft(left2);
        left1.setRight(right2);

        TreeNode left3 = new TreeNode(6);
        TreeNode right3 = new TreeNode(7);
        right1.setLeft(left3);
        right1.setRight(right3);

        return root;
    }
}
